package com.javastudy.autowiredStudy.getrongqi;

import com.javastudy.autowiredStudy.strategy.IntegerToStringOfListConverter;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

/**
 * 获取ioc容器方式之三： 通过这个可以可以使用
 */
@Service
public class GetIOCByApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
    private ApplicationContext applicationContext;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        this.applicationContext = contextRefreshedEvent.getApplicationContext();
    }

    public void getIOC() {
        IntegerToStringOfListConverter integerToStringOfListConverter = (IntegerToStringOfListConverter) applicationContext.getBean("integerToStringOfListConverter");
        System.out.println("integerToStringOfListConverter = " + integerToStringOfListConverter);
    }
}
